package com.yosaa.back.enums;

import com.yosaa.back.utils.TimeUtils;

public enum MaleEnduranceRunScore {
    EXCELLENT_100(100, "3:17.0", "3:15.0"),
    EXCELLENT_95(95, "3:22.0", "3:20.0"),
    EXCELLENT_90(90, "3:27.0", "3:25.0"),
    GOOD_85(85, "3:34.0", "3:32.0"),
    GOOD_80(80, "3:42.0", "3:40.0"),
    PASS_78(78, "3:47.0", "3:45.0"),
    PASS_76(76, "3:52.0", "3:50.0"),
    PASS_74(74, "3:57.0", "3:55.0"),
    PASS_72(72, "4:02.0", "4:00.0"),
    PASS_70(70, "4:07.0", "4:05.0"),
    PASS_68(68, "4:12.0", "4:10.0"),
    PASS_66(66, "4:17.0", "4:15.0"),
    PASS_64(64, "4:22.0", "4:20.0"),
    PASS_62(62, "4:27.0", "4:25.0"),
    PASS_60(60, "4:32.0", "4:30.0"),
    FAIL_50(50, "4:52.0", "4:50.0"),
    FAIL_40(40, "5:12.0", "5:10.0"),
    FAIL_30(30, "5:32.0", "5:30.0"),
    FAIL_20(20, "5:52.0", "5:50.0"),
    FAIL_10(10, "6:12.0", "6:10.0");

    private final int score;
    private final float freshmanSophomore; // 大一大二标准（秒）
    private final float juniorSenior; // 大三大四标准（秒）

    MaleEnduranceRunScore(int score, String freshmanSophomore, String juniorSenior) {
        this.score = score;
        this.freshmanSophomore = TimeUtils.convertToSeconds(freshmanSophomore);
        this.juniorSenior = TimeUtils.convertToSeconds(juniorSenior);
    }

    public int getScore() {
        return score;
    }

    public float getFreshmanSophomore() {
        return freshmanSophomore;
    }

    public float getJuniorSenior() {
        return juniorSenior;
    }

    /**
     * 根据成绩和年级计算分数
     *
     * @param time  成绩（秒）
     * @param grade 年级
     * @return 分数
     */
    public static float calculateScore(float time, String grade) {
        for (MaleEnduranceRunScore standard : MaleEnduranceRunScore.values()) {
            float threshold = grade.equals("大一") || grade.equals("大二")
                    ? standard.getFreshmanSophomore()
                    : standard.getJuniorSenior();
            if (time <= threshold) {
                return standard.getScore();
            }
        }
        return 0; // 默认分数
    }
}